<?php
  include 'header.php';
  
  if ($_SESSION['signed_in'] == false | $_SESSION['user_level'] != 1) {
      //the user is not an admin
      header('location: signin.php');
      echo '<br /><a href="index.php?id=' . htmlentities($_GET['p']) . '">Back to index</a>.';
  } else {
      if (mysql_real_escape_string($_GET['delete']) == "") {
          echo "<hr><br /><a href='delete_post.php?delete=topics'>DELETE ALL TOPICS</a><br />";
          echo "<hr><br /><a href='delete_post.php?delete=categories'>DELETE ALL CATEGORIES</a><br />";
      } else {
          if (mysql_real_escape_string($_GET['delete']) == "topics") {
              $result = mysql_query("DELETE FROM " . $table_prefix . "topics WHERE topic_id != 0");
              if ($result) {
                  echo "All topics deleted. Altering tables...<br />";
              }
              $alter = mysql_query("ALTER TABLE " . $table_prefix . "topics AUTO_INCREMENT=1");
              if ($alter) {
                  echo "Altering topics complete!<br /><br />";
              }
              
              $result2 = mysql_query("DELETE FROM " . $table_prefix . "posts WHERE post_id != 0");
              if ($result2) {
                  echo "All posts deleted. Altering tables...<br />";
              }
              
              $alter2 = mysql_query("ALTER TABLE " . $table_prefix . "topics AUTO_INCREMENT=1");
              if ($alter2) {
                  echo "Altering posts complete!<br />";
              }
              
              $result2 = "UPDATE users SET user_posts = 0 WHERE user_id = 2";
              
              echo "<br /><b>Operation completed!</b><br />";
              include('./adm/admin_synch_posts.php');
          }
          
          
          if (mysql_real_escape_string($_GET['delete']) == "categories") {
              $result = mysql_query("DELETE FROM " . $table_prefix . "categories WHERE cat_id != 0");
              if ($result) {
                  echo "All categories deleted. Altering tables...<br />";
              }
              $alter = mysql_query("ALTER TABLE " . $table_prefix . "categories AUTO_INCREMENT=1");
              if ($alter) {
                  echo "Altering categories complete!<br /><br />";
              }
              
              $result2 = "UPDATE " . $table_prefix . "users SET user_posts = '0' WHERE user_id = '2'";
              
              
              echo "<br /><b>Operation completed!</b><br />";
              include('./adm/admin_synch_posts.php');
          }
      }
  }
  
  if ($pageTitle = "") {
      $pageTitle = $l_forumname;
  }
  // Get all the page's HTML into a string
  $pageContents = ob_get_contents();
  // Wipe the buffer 
  ob_end_clean();
  echo str_replace('<!--TITLE-->', $pageTitle, $pageContents);
  if ($hide_footer != 1) {
      include 'footer.php';
  }
?>